package com.reactive.springbootreactive.config.security;

import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextImpl;
import org.springframework.security.web.server.context.ServerSecurityContextRepository;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.Arrays;

public class ServerSecurityContextRepositoryMy implements ServerSecurityContextRepository {
    @Override
    public Mono<Void> save(ServerWebExchange exchange, SecurityContext context) {
        System.out.println(this.getClass().getName() + "save");
        return null;
    }

    @Override
    public Mono<SecurityContext> load(ServerWebExchange exchange) {
        System.out.println(this.getClass().getName() + "load");
        SimpleGrantedAuthority admin = new SimpleGrantedAuthority("ADMIN");
        return Mono.just(new SecurityContextImpl(new UsernamePasswordAuthenticationToken(null, null, Arrays.asList(admin))));
    }
}
